
<template>
<h1>员工列表练习</h1>
  <input type="text" placeholder="请输入员工姓名" v-model="emp.name">
  <input type="text" placeholder="请输入员工工资" v-model="emp.salary">
  <input type="text" placeholder="请输入员工工作岗位" v-model="emp.job">
  <button @click="add()">添加员工</button>
  <hr>
  <table border="1">
    <tr>
      <th>编号</th>
      <th>姓名</th>
      <th>工资</th>
      <th>工作岗位</th>
    </tr>
    <tr v-for="(item, index) in arr" :key="index">
      <td>{{ index + 1 }}</td>
      <td>{{ item.name }}</td>
      <td>{{ item.salary }}</td>
      <td>{{ item.job }}</td>
    </tr>
  </table>
</template>

<script setup>
import { ref } from 'vue';
const emp = ref({
  name: '',
  salary: '',
  job: ''
});

const arr = ref([]);
const add = () => {
  if (emp.value.name.trim() == ''){
    alert('请输入员工姓名');
    return;
  }else if (emp.value.salary.trim() == ''){
    alert('请输入员工工资');
    return;
  }else if (emp.value.job.trim() == ''){
    alert('请输入员工工作岗位');
    return;
  }else{
    arr.value.push(emp.value);
    alert('添加成功');
    emp.value={};
  }



}
console.log(arr.value);


</script>

<style scoped>

</style>